package com.itchu.customer;

import com.itchu.common.domain.PageResult;
import com.itchu.system.domain.Song;
import com.itchu.system.domain.SongList;
import com.itchu.system.service.SongListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/api/songlist")
public class vSongListController {

    @Autowired
    private SongListService songListService;

    /**
     * 查找歌单的分页信息
     * @param key   搜索条件
     * @param page  当前页
     * @param rows  页大小
     * @param sortBy
     * @param desc
     * @return
     */
    @GetMapping("/page")
    public ResponseEntity<PageResult<SongList>> findByPage(
            @RequestParam(value = "key", required = false) String key,
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "rows", defaultValue = "15") Integer rows,
            @RequestParam(value = "sortBy", required = false) String sortBy,
            @RequestParam(value = "desc", required = false) Boolean desc
    ) {
        PageResult<SongList> list = songListService.findByPage(key,page,rows,sortBy,desc);
        return ResponseEntity.ok(list);
    }

    /**
     * 根据歌单的id查找歌曲列表信息
     * @param id  歌单id
     * @return
     */
    @GetMapping("/list/song")
    public ResponseEntity<List<Song>> findListSongByLid(
            @RequestParam("id") Long id
    ){
        List<Song> list = songListService.findListSongByLid(id);
        return ResponseEntity.ok(list);
    }


    /**
     * 根据分类的id查找歌单列表
     * @param page     当前页
     * @param rows     页大小
     * @param cid      分类id
     * @param isParent  是否是一级分类
     * @return
     */
    @GetMapping("/of/category")
    public ResponseEntity<PageResult<SongList>> findSongListByCategoryId(
            @RequestParam(value = "page",defaultValue = "1") Integer page,
            @RequestParam(value = "rows",defaultValue = "25") Integer rows,
            @RequestParam(value = "cid") Long cid,
            @RequestParam(value = "isParent") Long isParent
    ) {
        PageResult<SongList> list = songListService.findSongListByCategoryId(page,rows,cid,isParent);

        return ResponseEntity.ok(list);
    }

    /**
     * 按名字做模糊搜索
     * @param name
     * @return
     */
    @GetMapping("search/SongLists")
    public ResponseEntity<List<SongList>> searchSongListsByName(
            @RequestParam(value = "name") String name
    ) {
        List<SongList> list = songListService.searchSongListsByName(name);

        return ResponseEntity.ok(list);
    }
}
